#include "GameObject.h"
mtBEGIN(GameObject)
	mtSIGNAL(eventUpdate);
mtEND

#include <vector>
#include <algorithm>

namespace impl
{
	std::vector<GameObject*> objects;
}

Signal<void()> GameObject::eventUpdateAll;

GameObject::GameObject() :
	_isEnebled(true)
{
	impl::objects.push_back(this);
	_slotUpdate = connect(eventUpdateAll, this, &GameObject::update);
}

void GameObject::start()
{
	sendMessage(ECS::getStaticStringHash("onStart"));
}

void GameObject::destroy()
{

}

bool GameObject::isEnabled() const
{
	return _isEnebled;
}

void GameObject::setEnabled(bool enabled)
{
	if (_isEnebled != enabled)
		return;
	_isEnebled = enabled;
	if (enabled)
	{
		_slotUpdate.reconnect();
	}
	else
	{
		_slotUpdate.disconnect();
	}
}

void GameObject::updateAll()
{
	eventUpdateAll();
}

void GameObject::update()
{
	eventUpdate();
}
